home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / BlasterA.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  8.6 KB  |  298 lines

  1. class classes.enemy.BlasterA
  2. {
  3.    var x;
  4.    var y;
  5.    var color;
  6.    var moveScript;
  7.    var id;
  8.    var clip;
  9.    var colorR;
  10.    var trans;
  11.    var colorTrans;
  12.    var f2;
  13.    var dir;
  14.    var axis;
  15.    var xDest;
  16.    var yDest;
  17.    var oldDir;
  18.    var xMov = 0;
  19.    var yMov = 0;
  20.    var xMovT = 0;
  21.    var yMovT = 0;
  22.    var speedOrig = 6;
  23.    var speed = 6;
  24.    var xDestMet = false;
  25.    var yDestMet = false;
  26.    var c = 0;
  27.    var life = 75;
  28.    var nc = 0;
  29.    var xA = 0;
  30.    var yA = 0;
  31.    var nudging = false;
  32.    var power = 20;
  33.    var hc = 0;
  34.    var Name = "blasterA";
  35.    function BlasterA(px, py, pcolor, pmoveScript, pid)
  36.    {
  37.       this.x = px;
  38.       this.y = py;
  39.       this.color = pcolor;
  40.       this.moveScript = pmoveScript.slice();
  41.       this.id = pid;
  42.       _root.d = _root.d + 1;
  43.       this.clip = _root.attachMovie("blasterA","blasterA" + this.id + "Clip",_root.d + 50000);
  44.       this.clip._x = this.x;
  45.       this.clip._y = this.y;
  46.       this.speed *= _root.dif.speed;
  47.       this.speedOrig = this.speed;
  48.       this.life *= _root.dif.life;
  49.       this.colorR = _root.randRange(-10,30);
  50.       this.trans = new flash.geom.Transform(this.clip);
  51.       this.colorTrans = new flash.geom.ColorTransform(1,1,1,1,this.colorR,this.colorR,this.colorR,0);
  52.       this.trans.colorTransform = this.colorTrans;
  53.       this.clip.front.gotoAndStop(this.color);
  54.       this.parseMoveScript();
  55.       _root.stats.created = _root.stats.created + 1;
  56.    }
  57.    function nudge(pxA, pyA, pscale)
  58.    {
  59.       this.nc = 0;
  60.       this.nudging = true;
  61.       var _loc2_ = pscale / 400;
  62.       this.xA = pxA * _loc2_;
  63.       this.yA = pyA * _loc2_;
  64.    }
  65.    function bombed(num)
  66.    {
  67.       if(_root.subLevel != "3_1")
  68.       {
  69.          this.f2 = "death";
  70.       }
  71.    }
  72.    function parseMoveScript()
  73.    {
  74.       var _loc2_ = this.dir;
  75.       this.dir = this.moveScript[0];
  76.       if(this.dir == "break")
  77.       {
  78.          delete this.moveScript;
  79.          this.f2 = "";
  80.          this.dir = _loc2_;
  81.          this.blast();
  82.       }
  83.       else
  84.       {
  85.          this[this.axis + "MovT"] = 0;
  86.          this.f2 = "gotoXYDest";
  87.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  88.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  89.          if(this.dir == "L" || this.dir == "U")
  90.          {
  91.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  92.          }
  93.          else
  94.          {
  95.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  96.          }
  97.          this.moveScript.splice(0,2);
  98.       }
  99.    }
  100.    function gotoXYDest()
  101.    {
  102.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  103.       {
  104.          if(this.axis == "x")
  105.          {
  106.             this.x = this.xDest;
  107.          }
  108.          else
  109.          {
  110.             this.y = this.yDest;
  111.          }
  112.          this.parseMoveScript();
  113.       }
  114.    }
  115.    function getDirString()
  116.    {
  117.       if(this.xMovT < -1)
  118.       {
  119.          this.dir = "L";
  120.       }
  121.       else if(this.xMovT > 1)
  122.       {
  123.          this.dir = "R";
  124.       }
  125.       else if(this.yMovT > 1)
  126.       {
  127.          this.dir = "D";
  128.       }
  129.       else if(this.yMovT < -1)
  130.       {
  131.          this.dir = "U";
  132.       }
  133.    }
  134.    function leaving()
  135.    {
  136.       this.xMovT * 1.04;
  137.    }
  138.    function blast()
  139.    {
  140.       this.xMovT = 0;
  141.       this.yMovT = 0;
  142.       this.clip.blaster.gotoAndPlay("go");
  143.       this.clip.flame.gotoAndPlay("still");
  144.       this.f2 = "blasting";
  145.       this.c = 0;
  146.       _root.audio.playLevel2("blaster" + (random(3) + 1),_root.randRange(35,45));
  147.    }
  148.    function blasting()
  149.    {
  150.       this.c = this.c + 1;
  151.       if(this.c == 16)
  152.       {
  153.          var _loc3_ = this.dir != "L" ? 39 : 0;
  154.          _root["blasterALaser" + this.id] = new classes.shots.BlasterALaser(this.x + _loc3_,this.y,this.color,this.dir,this.id);
  155.          _root.addEnemyShot("blasterALaser" + this.id);
  156.          var _loc4_ = this.dir != "L" ? -100 : 100;
  157.          this.nudge(_loc4_,0,100);
  158.       }
  159.    }
  160.    function stopBlast()
  161.    {
  162.       this.xMovT = this.dir != "L" ? 15 : -15;
  163.       this.f2 = "leaving";
  164.       this.clip.flame.gotoAndPlay("start");
  165.    }
  166.    function death()
  167.    {
  168.       _root.stats.destroyed = _root.stats.destroyed + 1;
  169.       _root.stats.score += 25000;
  170.       _root.powerUp(this.x,this.y,90);
  171.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(90,140),_root.randRange(80,100),"Red"]);
  172.       _root.createExploA([this.x + this.clip._width / 2 + _root.randRange(-30,30),this.y + this.clip._height / 2 + _root.randRange(-30,30),_root.randRange(40,80),_root.randRange(70,100),"Purple"]);
  173.       _root.createExploA([this.x + this.clip._width / 2 + _root.randRange(-30,30),this.y + this.clip._height / 2 + _root.randRange(-30,30),_root.randRange(50,80),_root.randRange(50,100),"Red"]);
  174.       _root.createPowerUp([this.x,this.y,"coin25"]);
  175.       _root.audio.playLevel4("blasterX" + (random(3) + 1),_root.randRange(25,35));
  176.       var _loc3_ = 0;
  177.       var _loc4_ = random(4) + 2;
  178.       while(_loc3_ < _loc4_)
  179.       {
  180.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"blasterA" + this.color,"Purple"]);
  181.          _loc3_ = _loc3_ + 1;
  182.       }
  183.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"blue"]);
  184.       _root.audio.playLevel4("blasterX",_root.randRange(25,35));
  185.       _root.removeChar("blasterA" + this.id);
  186.       this.f2 = "";
  187.    }
  188.    function death2()
  189.    {
  190.       _root.removeChar("blasterA" + this.id);
  191.       this.f2 = "";
  192.    }
  193.    function main()
  194.    {
  195.       this[this.f2]();
  196.       if(this.oldDir != this.dir)
  197.       {
  198.          this.clip.gotoAndStop(this.dir);
  199.       }
  200.       this.oldDir = this.dir;
  201.       if(this.nudging)
  202.       {
  203.          this.xA *= 0.7;
  204.          this.yA *= 0.7;
  205.          this.nc = this.nc + 1;
  206.          var _loc8_ = 255 - this.nc * 17;
  207.          if(this.color == "Orange")
  208.          {
  209.             this.colorTrans.redOffset = _loc8_;
  210.             this.colorTrans.greenOffset = _loc8_ / 2;
  211.          }
  212.          else if(this.color == "Blue")
  213.          {
  214.             this.colorTrans.blueOffset = _loc8_;
  215.             this.colorTrans.greenOffset = _loc8_ / 2;
  216.          }
  217.          else
  218.          {
  219.             this.colorTrans.greenOffset = _loc8_;
  220.          }
  221.          this.trans.colorTransform = this.colorTrans;
  222.          if(this.nc == 15)
  223.          {
  224.             this.xA = this.yA = 0;
  225.             this.nudging = false;
  226.             this.colorTrans.blueOffset = this.colorR;
  227.             this.colorTrans.greenOffset = this.colorR;
  228.             this.colorTrans.redOffset = this.colorR;
  229.             this.trans.colorTransform = this.colorTrans;
  230.          }
  231.       }
  232.       var _loc4_ = 0;
  233.       var _loc7_ = _root.broShots.length;
  234.       while(_loc4_ < _loc7_)
  235.       {
  236.          var _loc6_ = _root.broShots[_loc4_] + "Clip";
  237.          if(this.clip.hitTest(_root[_loc6_]))
  238.          {
  239.             var _loc3_ = _root.broShots[_loc4_];
  240.             var _loc5_ = this.life;
  241.             this.life -= _root[_loc3_].power;
  242.             if(this.life < 1)
  243.             {
  244.                this.f2 = "death";
  245.             }
  246.             else
  247.             {
  248.                this.nudge(_root[_loc3_].xMov,_root[_loc3_].yMov,10);
  249.                _root.audio.playLevel4("batHit" + (random(2) + 1),_root.randRange(20,35));
  250.             }
  251.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  252.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  253.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  254.             _root[_loc3_].hit(_loc5_);
  255.             break;
  256.          }
  257.          _loc4_ = _loc4_ + 1;
  258.       }
  259.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  260.       {
  261.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  262.          this.f2 = "death";
  263.       }
  264.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  265.       {
  266.          this.f2 = "death2";
  267.       }
  268.       if(this.xMovT < this.xMov)
  269.       {
  270.          this.xMov -= 0.3;
  271.       }
  272.       else if(this.xMovT > this.xMov)
  273.       {
  274.          this.xMov += 0.3;
  275.       }
  276.       else
  277.       {
  278.          this.xMov = this.xMovT;
  279.       }
  280.       if(this.yMovT < this.yMov)
  281.       {
  282.          this.yMov -= 0.3;
  283.       }
  284.       else if(this.yMovT > this.yMov)
  285.       {
  286.          this.yMov += 0.3;
  287.       }
  288.       else
  289.       {
  290.          this.yMov = this.yMovT;
  291.       }
  292.       this.x += this.xMov + this.xA;
  293.       this.y += this.yMov + this.yA + 0.5 * Math.sin(this.hc += 0.05);
  294.       this.clip._x = this.x;
  295.       this.clip._y = this.y;
  296.    }
  297. }
  298.